package com.oba.king.datalib;

import java.util.List;

import com.oba.base.dao.BaseDao;
import com.oba.base.interfaces.IHsqlBuilder;
import com.oba.king.datalib.creditcontrol.CreditControl;
import com.oba.king.sysmanager.area.Area;

public class CustomerDao extends BaseDao{
	
	public IHsqlBuilder findAll() {
		return getSqlBuilder("from Customer c order by c.customerName");
	}

	public IHsqlBuilder findByCustomer(CustomerCondition customerCondition) {
		IHsqlBuilder sql = getSqlBuilder("from Customer c");
		sql.add("c.customerName like ?", customerCondition.getCustomerName(), "%", "%");
		sql.add("c.customerCode = ?", customerCondition.getCustomerCode());
		sql.add("c.creditControl.creditRate = ?", customerCondition.getCreditRate());
		sql.add("c.sellMethod like ?", customerCondition.getSaleMethod(), "%", "%");
		sql.add("c.businessManager = ?",customerCondition.getBusinessManager());
		sql.add("c.agentContactPerson = ?",customerCondition.getAgentContactPerson());
		if(customerCondition!=null&&!customerCondition.getAgentStatus().equals("o")){
		sql.add("c.agentStatus = ?",customerCondition.getAgentStatus());
		}
		sql.add("c.area = ?",customerCondition.getArea());
		sql.addend("order by c.customerName");
		return sql;

	}
	
	public List<Area> findAllArea(){
		return find("from Area a where a.parent is not null order by a.areaName");
	}
       
	public List<CreditControl> findAllCreditControl(){
		return find("from CreditControl cc order by cc.creditRate");
		
	}
}
